package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
/*@CrossOrigin("*")
@CrossOrigin({"http://manage.leyou.com","www.jd.com"})*/
//@CrossOrigin  //解决跨域
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父类id查询子类集合
     * @param id   父id
     * @return     返回分类集合
     */
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam("pid") Long id){
        // 通过service查询子分类
        List<CategoryDTO> resultList = categoryService.queryCategoryByParentId(id);
        // 返回
        return ResponseEntity.ok(resultList);
    }

    @GetMapping("/category/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(categoryService.queryCategoryByIds(ids));
    }
}
